package com.xzp.bams.entity;

import com.xzp.bams.exception.BalanceNotEnoughException;

import java.io.Serializable;

/**
 * @TODO
 * @Author xu
 * 2025/3/7
 */
public class CreditAccount extends Account  {
    private double ceiling;

    public CreditAccount() {
    }

    public CreditAccount(Long id, String password, String name, String personId, String email, double balance, double ceiling) {
        super(id, password, name, personId, email, balance);
        this.ceiling = ceiling;
    }


    public CreditAccount(double ceiling) {
        this.ceiling = ceiling;
    }

    /**
     * 获取
     *
     * @return ceiling
     */
    public double getCeiling() {
        return ceiling;
    }

    /**
     * 设置
     *
     * @param ceiling
     */
    public void setCeiling(double ceiling) {
        this.ceiling = ceiling;
    }

    @Override
    public Account withdraw(double money) throws BalanceNotEnoughException{
        //余额 + 透支额度 是否足够取钱
        if(this.getBalance()+this.ceiling>=money){
            //余额 是否足够取钱
            if(this.getBalance()>=money){
                this.setBalance(this.getBalance()-money);
            }else{
                this.ceiling-=money-this.getBalance();
                this.setBalance(0.0);
            }
            return this;
        }
        /*System.out.println("您的银行卡余额不足~");
        return this;*/
        throw new BalanceNotEnoughException("您的银行卡余额不足~");
    }

    @Override
    public String toString() {
        return  super.toString() +
                " , ceiling=" + ceiling +
                "} ";
    }
}
